package com.xbongbong.saas.model;

import com.xbongbong.paas.elasticsearch.pojo.dto.InsertDTO;
import com.xbongbong.paas.enums.IndexTypeEnum;
import com.xbongbong.paas.toolbox.exception.XbbException;
import com.xbongbong.paas.toolbox.wrap.IModel;
import com.xbongbong.pro.domain.entity.UpdateDataEntity;
import com.xbongbong.saas.domain.entity.PaymentBalanceEntity;
import org.elasticsearch.action.support.WriteRequest;

import java.util.Collection;
import java.util.List;

/**
 * 预付款余额
 * @author 梁鲁江
 * @version v1.0
 * @date 2019/11/7 10:11
 * @since v1.0
 */
public interface PaymentBalanceModel extends IModel<PaymentBalanceEntity> {
    /**
     * 保存账户余额
     * @param paymentBalanceEntity
     * @return
     */
    Integer save(PaymentBalanceEntity paymentBalanceEntity)  throws XbbException;

    PaymentBalanceEntity getByCustomerId(Long customerId,  String corpid)  throws XbbException;

    /**
     * 通过id获取数据
     * @param id
     * @param corpid
     * @return
     * @throws XbbException
     */
    PaymentBalanceEntity getById(Long id,  String corpid)  throws XbbException;
    
    /**
     * 根据客户IDList获取余额
     * @param customerId
     * @param corpid
     * @return
     * @throws XbbException
     */
     List<PaymentBalanceEntity> getByCustomerIds(Collection<Long> customerId, String corpid) throws XbbException;

    /**
     * 批量更新金额和时间
     * @param list
     * @param corpid
     * @return
     * @throws XbbException
     */
     Integer updateBatchByCorpidAndCustomerId(List<PaymentBalanceEntity> list,  String corpid) throws XbbException;
    /**
     * 删除预收款余额记录（保证余额=0才能删除）
     * @param idIn
     * @param corpid
     * @return
     */
     Integer deleteBatch(List<Long> idIn, String corpid) throws XbbException;
    /**
     * 删除预收款余额记录（保证余额=0才能删除）
     * @param idIn
     * @param corpid
     * @return
     */
     Integer deleteBatchRollback(List<Long> idIn, String corpid) throws XbbException;

    /**
     * 更新金额和del
     * @param entity
     * @param updateDel
     * @return
     * @throws XbbException
     */
    Integer update(PaymentBalanceEntity entity,boolean updateDel) throws XbbException;

    /**
     * 根据corpid和id更新（注：该方法直接更新客户的预收款余额，而不是对原值增加）
     * @param entity
     * @return
     */
    Integer updatePaymentBalanceById(PaymentBalanceEntity entity) throws XbbException;

    /**
     * 批量更新预收款余额：直接重置余额值，只用于脚本
     * @param corpid
     * @param list
     * @throws XbbException
     * @author zcp
     * @since v1.0
     * @version v1.0
     */
    void updateBatchAdvance(String corpid, List<PaymentBalanceEntity> list) throws XbbException;

    /**
     * 得到更新es的dto
     * @param paymentBalanceEntity
     * @param indexTypeEnum
     * @return com.xbongbong.paas.elasticsearch.pojo.dto.InsertDTO
     * @throws XbbException
     * @author zcp
     * @since v1.0
     * @version v1.0
     */
    InsertDTO getSaveDTO(PaymentBalanceEntity paymentBalanceEntity, IndexTypeEnum indexTypeEnum) throws XbbException;

    Integer updateTime(Long id,String corpid) throws XbbException ;

    /**
     * 批量更新
     * @param list  数据列表
     * @param corpid 公司id
     * @return Integer
     * @throws XbbException XbbException
     */
    Integer updateBatch(List<UpdateDataEntity> list, String corpid) throws XbbException;

    /**
     * 批量更新
     * @param list  数据列表
     * @param corpid 公司id
     * @param refreshPolicy 是否等待
     * @return Integer
     * @throws XbbException XbbException
     */
    Integer updateBatch(List<UpdateDataEntity> list, String corpid, WriteRequest.RefreshPolicy refreshPolicy) throws XbbException;

}
